package com.example.ycdyus.dailyfruit.utils;

import android.content.Context;

import com.nostra13.universalimageloader.cache.disc.DiskCache;
import com.nostra13.universalimageloader.cache.disc.impl.LimitedAgeDiskCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import java.io.File;

/**
 * Created by ycdyus on 2015/10/9.
 */
public class ImageLoaderUtils {
    public static void initImageLoader(Context context){
        //全局配置imageloader
        ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(context);
        /**
         * 这个方法可能有的机型不支持
         */
//        String path = context.getExternalCacheDir().getAbsolutePath() + File.separator  + "image";
        DiskCache diskCache = new LimitedAgeDiskCache(FileUtil.getImageCache(), 50 * 1024 * 1024);
        builder.diskCache(diskCache);
        builder.diskCacheFileNameGenerator(new Md5FileNameGenerator());
        builder.memoryCacheSize(4 * 1024 * 1024);
        builder.threadPoolSize(4);
        ImageLoader.getInstance().init(builder.build());
    }
}
